added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / wrappednamespace.cs
blob6d8cf1c5dc97aa6625cd5dcf96039f19367c1a48
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using Microsoft.JScript.Vsa;
19 using System;
20 using System.Reflection;
22 internal sealed class WrappedNamespace : ActivationObject{
23 internal String name;
25 internal WrappedNamespace(String name, VsaEngine engine)
26 : this(name, engine, true) {
29 internal WrappedNamespace(String name, VsaEngine engine, bool AddReferences)
30 : base(null) {
31 this.name = name;
32 this.engine = engine;
33 this.isKnownAtCompileTime = true;
34 if (name.Length > 0 && AddReferences)
35 engine.TryToAddImplicitAssemblyReference(name);
38 public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr){
39 FieldInfo cachedfield = (FieldInfo)(this.name_table[name]);
40 if (cachedfield != null) return new MemberInfo[]{cachedfield};
42 FieldAttributes attrs = FieldAttributes.Literal;
43 String fullname = this.name == null || this.name.Length == 0 ? name : this.name+"."+name;
44 Object t = null;
45 if (this.name != null && this.name.Length > 0)
46 t = this.engine.GetClass(fullname); //Packages will not have classes residing in the default name space
47 if (t == null){
48 t = this.engine.GetType(fullname);
49 if (t != null && !((Type)t).IsPublic){
50 if ((bindingAttr & BindingFlags.NonPublic) == 0)
51 t = null;
52 else
53 attrs |= FieldAttributes.Private;
55 }else{
56 if ((((ClassScope)t).owner.attributes&TypeAttributes.Public) == 0){
57 if ((bindingAttr & BindingFlags.NonPublic) == 0)
58 t = null;
59 else
60 attrs |= FieldAttributes.Private;
63 if (t == null) {
64 if (this.parent != null && (bindingAttr&BindingFlags.DeclaredOnly) == 0)
65 return this.parent.GetMember(name, bindingAttr);
66 return new MemberInfo[0];
69 JSGlobalField field = (JSGlobalField)this.CreateField(name, attrs, t);
70 if (engine.doFast)
71 field.type = new TypeExpression(new ConstantWrapper(Typeob.Type, null));
72 this.name_table[name] = field;
73 this.field_table.Add(field);
74 return new MemberInfo[]{field};
77 public override String ToString(){
78 return this.name;